<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@taglib prefix="s" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html><html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户资料</title>
    <style>
        body{
            width: 99%;
        }
        .newtitle {
            PADDING-LEFT: 15px;
            BACKGROUND: url('');
            PADDING-BOTTOM: 4px;
            BORDER-LEFT: #c0dcf2 1px solid;
        }
    </style>
    <jsp:include page="easyuiIncludeJS.jsp"/>
    <script type="text/javascript">

        var empid="";
        var empName="";

        $(function () {
            var pager = $(".easyui-datagrid").datagrid('getPager');
            $(pager).pagination({
                total:${pager.totalRows},
                pageSize:${pager.pageRow},
                displayMsg: '{from}-{to}/{total}',
                pageNumber:${pager.cur_page},
                afterPageText: '页，共{pages}页',
                pageList: [5, 10, 20, 30, 50, 100],
                loading: false,
                showPageList: true,
                showRefresh: true,
                //刷新方法
                onBeforeRefresh: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/emp/list?cur_page=" + p + "&pageRow=" + s;
                },
                onSelectPage: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/emp/list?cur_page=" + p + "&pageRow=" + s;
                }
            });
        });

        function del(id) {
            if (!confirm('删除确认')) {
                return;
            }
            window.location.href = "${pageContext.request.contextPath}/admin/emp/del?empId=" + id;
        }

        function szpassword(id) {
            if (!confirm('确认将员工密码重置为123456？')) {
                return;
            }
            alert('初始化密码成功,密码为123456');
            window.location.href = "${pageContext.request.contextPath }/admin/emp/szpassword?empId=" + id;
        }

        function edit(id) {
            window.location.href = "${pageContext.request.contextPath}/admin/emp/getById?empId=" + id;
        }

        function add() {
            window.location.href = "${pageContext.request.contextPath}/admin/emp/add";
        }

        function test(value, rec) {
            var id = rec.empId;
            $("#seId").val(id);
            var url = "${pageContext.request.contextPath }/admin/emp/json";
            $.post(
                url,
                {"empId": id},
                empsj,
                "json"
            );
        }
        function empsj(data) {
            empid=data.emp.empId;
            empName=data.emp.empName;
        }

        function dateFormatter (value) {
            var date = new Date(value);
            var year = date.getFullYear().toString();
            var month = (date.getMonth() + 1);
            var day = date.getDate().toString();
            var hour = date.getHours().toString();
            var minutes = date.getMinutes().toString();
            var seconds = date.getSeconds().toString();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            if (hour < 10) {
                hour = "0" + hour;
            }
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            if (seconds < 10) {
                seconds = "0" + seconds;
            }
            return year + "-" + month + "-" + day ;

        }

        function setStatus(status, empId) {
            var str = "";
            if (status == 1) {
                str = "是否启用";
            } else {
                str = "是否禁用";
            }
            if (confirm(str)) {
                window.location.href = "${pageContext.request.contextPath }/admin/emp/status?status=" + status + "&empId=" + empId;
            }

        }
        function ss() {
            if($("#empName").val().length>10){
                alert('员工姓名长度过长');
                return;
            }
            if($("#phone1").val().length>11){
                alert('手机号码长度过长');
                return;
            }
            document.forms[0].submit();
        }
    </script>
</head>
<body>
<div id="tb">
    <a class="easyui-linkbutton" plain="true" icon="icon-add" href="javascript:void(0);" onclick="add();">新增员工</a>
    <form id="form1" modelAttribute="enrollment" action="${pageContext.request.contextPath}/admin/emp/list" method="post">
        部门名称:
        <select  id="depId" name="depId"  style="width:120px;" >
            <c:forEach items="${listDep}" var="d">
                <c:if test="${d.depid==emp.depId}">
                    <option value="${d.depid}" selected="selected">${d.depName}</option>
                </c:if>
                <c:if test="${d.depid!=emp.depId}">
                    <option value="${d.depid}">${d.depName}</option>
                </c:if>
            </c:forEach>
        </select>
        员工姓名: <input class="easyui-textbox" id="empName" name="empName" value="${emp.empName}" style="width:110px;">
        手机号码: <input class="easyui-textbox" id="phone1" name="phone1" value="${emp.phone}" style="width:110px;">
        状态:
        <select class="easyui-combobox" panelHeight="auto" id="status" name="status" style="width:120px;" editable="false">
            <option value="-1" <c:if test="${emp.status==-1}">selected="selected"</c:if>>--未选择--</option>
            <option value="1" <c:if test="${emp.status==1}">selected="selected"</c:if>>启用</option>
            <option value="0" <c:if test="${emp.status==0}">selected="selected"</c:if>>禁用</option>
        </select>
        <a href="javascript:void(0);" class="easyui-linkbutton"  plain="true" onclick="ss();" iconCls="icon-search">搜索</a>
    </form>
</div>
<%--<div class="easyui-layout">--%>
<table class="easyui-datagrid" pagination="true" style="height:500px;width: auto;" fitColumns="true" singleSelect="true" data-options="onClickRow:test">
    <thead>
    <tr>
        <th width="55" align="center" field="empId">员工编号</th>
        <th width="55" align="center" field="empName">员工姓名</th>
        <th width="55" align="center" field="depId">部门</th>
        <th width="40" align="center" field="sex">性别</th>
        <th width="80" align="center" field="phone">手机号码</th>
        <th align="center" field="qqCode">QQ号码</th>
        <th width="110" align="center" field="address">家庭地址</th>
        <th width="40" align="center" field="status">状态</th>
        <th width="60" align="center" field="szstatus">设置状态</th>
        <th width="80" align="center" field="szpassword">初始密码</th>
        <th width="110" align="center" field="opt">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${pager.datas}" var="d">
        <tr>
            <td width="100">${d.empId}</td>
            <td width="100">${d.empName}</td>
            <td width="100">${d.depName}</td>
            <td width="100">${d.sex}</td>
            <td width="100">${d.phone}</td>
            <td>${d.qqCode}</td>
            <td width="100">${d.address}</td>
            <c:if test="${d.status==0}">
                <td width="100">禁用</td>
            </c:if>
            <c:if test="${d.status==1}">
                <td width="100">启用</td>
            </c:if>
            <c:if test="${d.status==0}">
                <td width="100"><a class="easyui-linkbutton" icon="icon-tip"  plain="true" href="javascript:void(0);"  onclick="setStatus(1,'${d.empId}');">启用</a></td>
            </c:if>
            <c:if test="${d.status==1}">
                <td width="100"><a class="easyui-linkbutton" icon="icon-tip"  plain="true" href="javascript:void(0);" onclick="setStatus(0,'${d.empId}');">禁用</a></td>
            </c:if>
            <td width="100">
                <a class="easyui-linkbutton" icon="icon-reload" plain="true" href="javascript:void(0);" onclick='szpassword(${d.empId})'>重置密码</a>
            </td>
            <td width="100">
                <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" icon="icon-remove"
                   onclick='del(${d.empId});'> 删除</a>
                <a href='javascript:void(0);' class="easyui-linkbutton" plain="true" icon="icon-edit"
                   onclick='edit(${d.empId});'>编辑</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
</body>
</html>
